package com.lz.springcloud.tools.service.impl;

import java.util.concurrent.TimeUnit;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import com.lz.springcloud.tools.service.RedisService;

@Service
public class RedisServiceImpl implements RedisService {

	@Autowired
	RedisTemplate<String, String> example;
	
	@Override
	public String get(final String key) {
		return (String) example.opsForValue().get(key);
	}

	@Override
	public boolean del(final String key) {
		return example.delete(key);
	}

	@Override
	public boolean set(final String key, String value) {
		example.opsForValue().set(key, value);
		return true;
	}

	@Override
	public void upd(final String key, String value) {
		example.opsForValue().getAndSet(key, value);
	}

	@Override
	public boolean expire(String key, Long time) {
		return example.expire(key, time, TimeUnit.SECONDS);
	}

}